

/**
 * 统计相关图表 echarts 配置项
 * @param {xData} x轴数据
 * @param {yData} y轴数据
 */
export default (xData, yData) => {
  /**xAxis */
  const xAxis = {
    type: 'category',
    data: xData,
    show: false,
  }

  /**yAxis */
  const yAxis = {
    type: 'value',
    axisLabel: {
      fontSize: '7.5',
      formatter(v) {
        v = v.toString()
        if (v >= 100000000000) {
          return v.substring(0, 5) / 10 + '亿'
        } else if (v >= 10000000000) {
          return v.substring(0, 4) / 10 + '亿'
        } else if (v >= 1000000000) {
          return v.substring(0, 3) / 10 + '亿'
        } else if (v >= 100000000) {
          return v.substring(0, 2) / 10 + '亿'
        } else if (v >= 10000000) {
          return v.substring(0, 4) + '万'
        } else if (v >= 1000000) {
          return v.substring(0, 3) + '万'
        } else if (v >= 100000) {
          return v.substring(0, 2) + '万'
        } else if (v >= 10000) {
          return v.substring(0, 2) / 10 + '万'
        } else if (v >= 1000) {
          return Math.floor(v / 1000) + '千'
        } else {
          return v
        }
      },
    },
  }


  /**
   * tooltip
   *  */
  const tooltip = {
    show: true,
    extraCssText: 'width:150px;height:40px;background:rgba(0,0,0,0.3);border:none',
    position: [40, 10],
    trigger: 'axis',
    textStyle: {
      fontSize: 12,
    },
    formatter: (params) => {
      const { data, dataIndex } = params[0]
      return `<div>
                <span style="color:white;">${xData[dataIndex]} :</span>
                <span style="color:green;font-weight:bold;">${data}</span>
              </div>
              `
    }
  }



  /** grid */
  const grid = {
    // 让图表占满容器
    containLabel: true,
    top: '5px',
    left: '2%',
    right: '10px',
    bottom: '-10px',
  }

  const series = [
    {
      data: yData,
      type: 'line',
      smooth: true,
      showSymbol: true,
      symbol: 'circle',
      symbolSize: 4,
    },
  ]



  return {
    tooltip,
    xAxis,
    yAxis,
    grid,
    series
  }
}
